package com.nettest.entity.system;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

import com.nettest.entity.BaseAuditable;


@Entity
@Table(name = "t_role")
public class Role extends BaseAuditable {
	
	private static final long serialVersionUID = -8718353308294990156L;

	@TableGenerator(
			name="idGen", 
			table="ID_GENERATOR", 
			pkColumnName="ID_KEY", 
			valueColumnName="ID_VALUE", 
			pkColumnValue="ROLE_ID", 
			allocationSize=1)
	@Id
	@GeneratedValue(strategy=GenerationType.TABLE, generator="idGen")
	@Column(name="id")
	private Long id;
	
	@Column(name="role_id",length=100)
	private String roleId;
	@Column(name="parent_id",length=100)
	private String parentId;
	
	@Column(name = "role_name", length=80, nullable=false)
	private String roleName;
	
	@Column(name = "memo", length=100)
	private String memo;
	
	@ManyToMany(mappedBy = "roles")
	private Set<Staff> staffs = new HashSet<Staff>();	
	
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "t_role_menu", joinColumns = @JoinColumn(name = "role_id"), inverseJoinColumns = @JoinColumn(name = "menu_id"))
	@OrderBy("menuId")
	private Set<Menu> menus = new HashSet<Menu>();

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public String getMemo() {
		return memo;
	}

	public void setMemo(String memo) {
		this.memo = memo;
	}

	public Set<Staff> getStaffs() {
		return staffs;
	}

	public void setStaffs(Set<Staff> staffs) {
		this.staffs = staffs;
	}

	public Set<Menu> getMenus() {
		return menus;
	}

	public void setMenus(Set<Menu> menus) {
		this.menus = menus;
	}

	public String getRoleId() {
		return roleId;
	}

	public void setRoleId(String roleId) {
		this.roleId = roleId;
	}

	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}
}
